import { createRouter, createWebHistory } from 'vue-router';
import Login from '../views/Login.vue';
import Register from '../views/Reg.vue';
import Home from '../views/Home.vue';
import Submit from '../views/Submit.vue';
import submitCenter from '../views/SubmitCenter.vue';
import CheckCenter from '../views/CheckCenter.vue';
import Check from '../views/Check.vue';
import AIchat from '../views/AIchat.vue';
import VideoCenter from '../views/VideoCenter.vue'; // 导入新组件

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/reg',
    name: 'Register',
    component: Register
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path:'/submit',
    name:'submit',
    component:Submit,
  },
  {
    path:'/submitCenter',
    name:'submitCenter',
    component:submitCenter,
  },
  {
    path: '/checkCenter',
    name: 'checkCenter',
    component: CheckCenter
  },
  {
    path: '/check',
    name: 'check',
    component: Check
  },
  {
    path: '/aichat',
    name: 'AIchat',
    component: AIchat,
  },
  {
    path: '/video-center',
    name: 'VideoCenter',
    component: VideoCenter
  }
];

const router = createRouter({
    history: createWebHistory(),
    routes: routes
})

router.beforeEach((to, from, next) => {
    if (to.meta.needLogin &&!sessionStorage.getItem('user')) {
        alert('请先登录');
        next('/login');
        return;
    }
    next();
})

export default router;